<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/js/self.js"></script>
    <script type="text/javascript" src="/resources/js/md5.js"></script>
    <script type="text/javascript" src="/resources/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/resources/js/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
    <script src="/resources/js/fk.js"></script>
    <link href="/resources/video/css/video-js.css" rel="stylesheet">
    <link href="/resources/css/fk_ymm.css?r=1" rel="stylesheet">
    <style>
        td{
            white-space:normal;
        }
        input{
            width: 80%;
        }
        textarea{
            width: 780px;
        }
    </style>
</head>
<body>
<input type="hidden" class="form-data" name="id"/>
<input type="hidden" class="form-data" name="policeCheckId">
<div>
    <button type="button" onclick="goBack()" class="btn btn-success" style="float: right;margin-right: 20px;">返回</button>
</div>
<div class="table-title">易制毒化学品管理监督检查表</div>
<div>
    <table>
        <tr>
            <td class="name" colspan="2">单位名称</td>
            <td class="value" colspan="4"><input class="form-data" name="companyName"  /></td>
        </tr>
        <tr>
            <td class="name" colspan="2">单位地址</td>
            <td class="value" colspan="4"><input class="form-data" name="address"  /></td>
        </tr>
        <tr>
            <td class="name" colspan="2">监督检查人</td>
            <td class="value" colspan="2"><input style="width:150px;" class="form-data" name="policeName" /></td>
            <td class="name">检查日期</td>
            <td class="value" colspan="2"><input class="form-data" name="checkDate"  /></td>
        </tr>
        <tr>
            <td class="name" width="40px" rowspan="4">检查项目</td>
            <td class="name" >名称</td>
            <td class="value" colspan="4"><input class="form-data" name="checkItem"  /></td>

        </tr>
        <tr>
            <td class="name" rowspan="3">资质</td>
            <td class="value" colspan="3">营业执照：有<input class="form-data" name="hasLicense" value="1" type="radio">
                无<input class="form-data" name="hasLicense" value="0" type="radio">
            </td>
            <td class="value">组织机构代码：有<input class="form-data" name="hasOrgCode"  value="1" type="radio">
                无<input class="form-data"  name="hasOrgCode"  value="0" type="radio">
            </td>
        </tr>
        <tr>
            <td class="value" colspan="4">易制毒化学品生产许可/备案证明（易制毒化学品生产单位）：
                有<input class="form-data" name="hasCreateRecord" value="1" type="radio">
                无<input class="form-data" name="hasCreateRecord" value="0" type="radio">
            </td>
        </tr>
        <tr>
            <td class="value" colspan="4">易制毒化学品经营许可/备案证明（易制毒化学品经营单位）：
                有<input class="form-data" name="hasOperRecord"  value="1" type="radio">
                无<input class="form-data" name="hasOperRecord" value="0" type="radio">
            </td>
        </tr>
        <tr>
            <td  class="name" rowspan="6"></td>
            <td class="name">培训</td>
            <td class="value" colspan="4">单位易制毒化学品知识培训：
                有组织开展<input class="form-data" name="learn" value="1" type="radio">
                未组织开展<input class="form-data" name="learn" value="0"  type="radio">
            </td>
        </tr>
        <tr>
            <td  class="name" rowspan="3" width="70">台帐检查</td>
            <td  class="name" width="70">生产单位</td>
            <td class="value" colspan="3">
                1、是否建立易制毒化学品生产、销售、出入库台账：
                <br>
                如实<input class="form-data" name="cRecord"  value="1" type="radio">
                不如实<input class="form-data" name="cRecord"  value="0" type="radio">
                无<input class="form-data" name="cRecord"  value="-1" type="radio">
                <br>

                2、销售情况是否及时报公安机关报备（一类易制毒化学品销售之日起五日内报，第二类、第三类易制毒化学品三十日内报）：
                <br>
                及时<input class="form-data" name="cIntime" value="1" type="radio">
                不及时<input class="form-data" name="cIntime" value="0" type="radio">
                <br>
                3、是否留存购买方购买许可证或备案证明以及购买经办人身份证明复印件 <br>
                有<input class="form-data" name="cCardRecord" value="1" type="radio">
                无<input class="form-data" name="cCardRecord" value="0" type="radio">
                不全<input class="form-data" name="cCardRecord" value="-1" type="radio">
            </td>
        </tr>
        <tr>
            <td  class="name" >经营单位</td>
            <td class="value"  colspan="3">
                1、是否建立易制毒化学品购买、销售、出入加台账： <br>
                如实<input class="form-data" name="bRecord"  value="1" type="radio">
                不如实<input class="form-data" name="bRecord"  value="0" type="radio">
                无<input class="form-data" name="bRecord"  value="-1" type="radio">
                <br>
                2、销售情况是否及时报公安机关报备（期限同生产单位）： <br>
                及时<input class="form-data" name="bIntime" value="1" type="radio">
                不及时<input class="form-data" name="bIntime" value="0" type="radio">
                <br>
                3、是否留存购买方购买许可证或备案证明以及购买经办人身份证明复印件： <br>
                有<input class="form-data" name="bCardRecord" value="1" type="radio">
                无<input class="form-data" name="bCardRecord" value="0" type="radio">
                不全<input class="form-data" name="bCardRecord" value="-1" type="radio">
            </td>
        </tr>
        <tr>
            <td  class="name" >使用单位</td>
            <td class="value"  colspan="3">
                1、是否建立易制毒化学品购买、出入库台账： <br>
                如实<input class="form-data" name="uRecord" value="1" type="radio">
                不如实<input class="form-data" name="uRecord" value="0" type="radio">
                无<input class="form-data" name="uRecord" value="-1" type="radio">
                <br>
                2、是否留存购买许可证或备案证明）： <br>
                有<input class="form-data" name="uAllow" value="1"  type="radio">
                无<input class="form-data" name="uAllow" value="0"  type="radio">
                不全<input class="form-data" name="uAllow" value="-1"  type="radio">
                <br>
                3、购买入库报备是否及时: <br>
                及时<input class="form-data" name="uIntime" value="1"  type="radio">
                不及时<input class="form-data" name="uIntime" value="0" type="radio">
            </td>
        </tr>
        <tr>
            <td class="name">
                票据
                核查
            </td>
            <td  colspan="4">
                1、是否存在现金交易（《条例》允许除外）： <br>
                有<input class="form-data" name="cashTrade" value="1"  type="radio">
                无<input class="form-data" name="cashTrade" value="0"  type="radio">
                <br>
                2、票据与台账是否相符： <br>
                相符<input class="form-data" name="tradeMatch" value="1"  type="radio">
                不相符<input class="form-data" name="tradeMatch" value="0"  type="radio">
            </td>
        </tr>
        <tr>
            <td class="name">
                仓储检查
            </td>
            <td colspan="4">
                1、出入库登记与实际存储是否相符 <br>
                相符<input class="form-data" name="storeMatch" value="1" type="radio">
                不相符<input class="form-data" name="storeMatch" value="0" type="radio">
                <br>
                2、中否存在安全隐患： <br>
                有<input class="form-data" name="danger"  value="1" type="radio">
                无<input class="form-data" name="danger"  value="0" type="radio">
            </td>
        </tr>
        <tr>
            <td class="name">检查存在问题
            </td>
            <td class="value" colspan="5">
                <div style="width: 90%;float:left">
                    <div> <textarea class="form-data" name="trouble" ></textarea></div>
                    <div>
                        <div id="trouble_div" style="margin-top: 20px;">
                        </div>
                    </div>
                </div>
                <div style="width: 10%;float:left">
                    <button class="btn btn-primary" onclick="$('#trouble_input').click();">
                        上传文件
                    </button>

                    <input type="file" id="trouble_input" name="file" onchange="uploadFileId('trouble')"
                           value="Upload your resume"
                           style="opacity: 0;width: 0px;display: none">
                </div>

            </td>

        </tr>
        <tr>
            <td class="name">整改意见
            </td>
            <td class="value" colspan="5">
                <div style="width: 90%;float:left">
                    <div> <textarea class="form-data" name="suggest"></textarea></div>
                    <div>
                        <div id="suggest_div" style="margin-top: 20px;">
                        </div>
                    </div>
                </div>
                <div style="width: 10%;float:left">
                    <button class="btn btn-primary" onclick="$('#suggest_input').click();">
                        上传文件
                    </button>

                    <input type="file" id="suggest_input" name="file" onchange="uploadFileId('suggest')"
                           value="Upload your resume"
                           style="opacity: 0;width: 0px;display: none">
                </div>

            </td>

        </tr>
        <tr>
            <td class="name">整改完成情况

            </td>
            <td class="value" colspan="5">
                <div style="width: 90%;float:left">
                    <div> <textarea class="form-data" name="receipt"></textarea></div>
                    <div>
                        <div id="receipt_div" style="margin-top: 20px;">
                        </div>
                    </div>
                </div>
                <div style="width: 10%;float:left">
                    <button class="btn btn-primary" onclick="$('#receipt_input').click();">
                        上传文件
                    </button>

                    <input type="file" id="receipt_input" name="file" onchange="uploadFileId('receipt')"
                           value="Upload your resume"
                           style="opacity: 0;width: 0px;display: none">
                </div>

            </td>

        </tr>
        <tr>

            <td colspan="4" style="padding: 0px !important;">
                <div class="name"  style="padding-left: 10px;height: 100%;width:30%;float:left">检查人员</div>
                <div class="value"  style="padding-left: 10px;width:70%;float:left">
                    <input class="form-data" name="checkMan" />
                </div>
            </td>
            <td colspan="2" style="padding: 0px !important;">
                <div class="name" style="padding-left: 10px;height: 100%;width:30%;float:left">
                    被检查单位负责人（单位盖章）
                </div>
                <div class="value" style="padding-left: 10px;width:70%;float:left">
                    <input class="form-data" name="companyPerson" />
                </div>
            </td>


        </tr>
    </table>
</div>
<div>
    <button type="button" onclick="save()" class="btn btn-success">保存</button>
    <!--<button type="button" onclick="goBack()" class="btn btn-success">返回</button>-->
</div>
</body>
<script type="application/javascript">
    $(function () {
        initData();

    });
    function initData(){
        var data = getData();
        var id = data.id;
        var policeCheckId = data.policeCheckId;
        if(null2empty(id) !==""){
            $("input[name='id']").val(id);
            $.ajax({
                url:"/admin/policeCheckTableOne/find.do",
                data:{'id':id},
                type:'post',
                dataType:'json',
                success:function(data){
                    console.log(data);
                    if(data.success){
                        debugger;
                        initPageDate(data.data, '.form-data');
                        addFileInfoToTable(data.data.troubleFileList,'trouble');
                        addFileInfoToTable(data.data.suggestFileList,'suggest');
                        addFileInfoToTable(data.data.receiptFileList,'receipt');

                    }
                }
            });

        }else if(null2empty(policeCheckId) !==""){
            $("input[name='policeCheckId']").val(policeCheckId);
        }

    }
    function save() {
        var params = getPageDataByClass("form-data");
        params.regulation = "";
        params.troubleFile="";
        params.suggestFile ="";
        params.receiptFile ="";
        $("input[name='trouble_id']").each(function(index,files){
            if(files == "") {
                params.troubleFile = $(this).val();
            } else {
                params.troubleFile = params.troubleFile + "," + $(this).val();
            }
        });
        $("input[name='suggest_id']").each(function(index,files){
            if(files == "") {
                params.suggestFile = $(this).val();
            } else {
                params.suggestFile = params.suggestFile + "," + $(this).val();
            }
        });
        $("input[name='receipt_id']").each(function(index,files){
            if(files == "") {
                params.receiptFile = $(this).val();
            } else {
                params.receiptFile = params.receiptFile + "," + $(this).val();
            }
        });
        $.ajax({
            url: "/admin/policeCheckTableOne/save.do",
            data: params,
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    alert("保存成功");
                    goBack();
                } else {
                    alert(data.msg);
                }
            }
        });
    }
    function addFileInfoToTable(fileInfoList,fileType){
        $(fileInfoList).each(function(index,file){
            var fileHtml = "<div  style='border-radius: 2px; width:100%;height:100px;float: left; border: 2px #ffffff solid;'>"+

                "<div align='center' style='height:80px;margin-bottom: 0px;'>"+
                "<div align='center' onclick='downLoadFile(\""+file.path+"\",\""+file.name+"\")' ><input type='hidden' name='"+fileType+"_id' value='"+file.id+"'>"+file.name+"</div>"+

                "<button  style='margin-left: 20px;' " +
                "onclick='downLoadFileId(\""+file.path+"\",\""+file.name+"\")' " +
                "name='download' extendData='"+file.id+"'class='btn btn-primary'>下载</button>"+
                "<button  style='margin-left: 20px;' name='delete' extendData='"+file.id+"'class='btn btn-primary'>删除</button><div>"
            "</div>";
            $("#"+fileType+"_div").html(fileHtml);

        });
        $("button[name='delete']").unbind('click');
        $("button[name='delete']").click(function(){
            var id = $(this).attr("extendData");
            $.ajax({
                type: "POST",
                url: "/file/delete.do?_t=" + new Date().getTime(),
                data: "fileId=" + id,

                success: function (result) {
                    alert("删除成功");
                },

                error: function (XMLHttpRequest, textStatus, thrownError) {
                    /* alert("系统异常");*/
                }
            });
            $(this).parent().parent().remove();
        });
    }
    function uploadFileId(fileType) {
        $.ajaxFileUpload({
            url: "/file/uploadFile.do?_t=" + new Date().getTime(),            //需要链接到服务器地址
            secureuri: false,//是否启用安全提交，默认为false
            fileElementId: fileType+'_input',                        //文件选择框的id属性
            dataType: 'text',                                     //服务器返回的格式，可以是json, xml
            success: function (data, status) {//服务器成功响应处理函数
                var rpeObj = $.parseJSON(data);
                var fileInfoList = rpeObj.data;
                addFileInfoToTable(fileInfoList,fileType);

            }
        });
    }
    function goBack() {
        goto("police_check_list.html");
    }
</script>
</html>